﻿using AutoMapper;
using TrackSystem.Contracts;
using TrackSystem.EntityFramework.Repositories;

namespace TrackSystem.EntityFramework
{
    public class RepositoryWrapper(TkDBContent dBContent, IMapper mapper) : IRepositoryWrapper
    {
        /// <summary>
        /// 通信通道数据表
        /// </summary>
        private IChannelRepository _channel = null!;
        public IChannelRepository Channel => _channel ??= new ChannelRepository(dBContent, mapper);

        /// <summary>
        /// 传感器数据表
        /// </summary>
        private ISensorRepository _sensor = null!;
        public ISensorRepository Sensor => _sensor ??= new SensorRepository(dBContent, mapper);

        /// <summary>
        /// 变量数据表
        /// </summary>
        private IVarRepository _var = null!;
        public IVarRepository Var => _var ??= new VarRepository(dBContent, mapper);

        /// <summary>
        /// 设备数据表
        /// </summary>
        private IEquipRepository _equip  = null!;
        public IEquipRepository Equip => _equip ??= new EquipRepository(dBContent,mapper);

        /// <summary>
        /// 逻辑变量
        /// </summary>
        private ILogicRepository _logic = null!;
        public ILogicRepository Logic => _logic ??= new LogicRepository(dBContent, mapper);

        /// <summary>
        /// 控制回路接口
        /// </summary>
        private ILoopRepository _loop = null!;
        public ILoopRepository Loop => _loop ??= new LoopRepository(dBContent, mapper);


        /// <summary>
        /// 控制回路接口
        /// </summary>
        private IAlarmRepository _alarm = null!;
        public IAlarmRepository Alarm => _alarm ??= new AlarmRepository(dBContent, mapper);
        
        /// <summary>
        /// 控制回路接口
        /// </summary>
        private ISlaveRepository _slave = null!;
        public ISlaveRepository Slave => _slave ??= new SlaveRepository(dBContent, mapper);

        /// <summary>
        /// 保存更改到数据库
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> SaveAsync()
        {
            return await dBContent.SaveChangesAsync();
        }

        /// <summary>
        /// 插入数据表
        /// </summary>
        /// <param name="recName"></param>
        public void InsertRecordTable(string recName)
        {
            dBContent.InsertRecordTable(recName);
        }
    }
}
